/* rcsois1b.p - Release Management Customer Schedules                   */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/* $Revision: 1.15 $                                                     */
/*                                                                      */
/* Revision: 1.13       BY: Dan Herman    DATE: 03/22/01   ECO: *P006* */
/* Revision: 1.14       BY: Dan Herman    DATE: 08/15/01   ECO: *P01L* */
/* $Revision: 1.15 $       BY: Dan Herman       DATE: 9/03/02 ECO: *P0HG*  */

/*V8:ConvertMode=NoConvert                                              */
/*                                                                          */
/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----  */
/*                                                                          */
/*         THIS PROGRAM IS A BOLT-ON TO STANDARD PRODUCT MFG/PRO.           */
/* ANY CHANGES TO THIS PROGRAM MUST BE PLACED ON A SEPARATE ECO THAN        */
/* STANDARD PRODUCT CHANGES.  FAILURE TO DO THIS CAUSES THE BOLT-ON CODE TO */
/* BE COMBINED WITH STANDARD PRODUCT AND RESULTS IN PATCH DELIVERY FAILURES.*/
/*                                                                          */
/* -----  W A R N I N G  -----  W A R N I N G  -----  W A R N I N G  -----  */
/*                                                                          */

/*------------------------------------------------------------------------
Purpose:       Update Shipment Detail Line Charges with the extended price.

Exceptions:    None
Conditions:
Pre:           Container and Line Charges must be enabled.
Post:
Notes:         The Quantity is always one.  We use abs_ship_qty to determine
               if the qty is positive or negative, to arrive at the
               extended line price.
History:

Inputs:
pAbsId          (character)
pShipFrom       (character)
pOrder          (character)
pOrderLine      (integer)
pAbsRecid       (recid)
pConfrim        (logical)
pForASN         (logical)

Outputs:

----------------------------------------------------------------------------*/

{mfdeclre.i}
{pxpgmmgr.i}
{pxphdef.i cclcxr}

define input parameter pAbsId       as character no-undo.
define input parameter pShipFrom    as character no-undo.
define input parameter pOrder       as character no-undo.
define input parameter pOrderLine   as integer no-undo.
define input parameter pAbsRecid    as recid no-undo.
define input parameter pConfirm     as logical no-undo.
define input parameter pForASN      as logical no-undo.

define shared variable auto_post like mfc_logical.

define variable vLinePrice as decimal no-undo.
define variable vLineUnitCharge as decimal no-undo.
define variable vExtendedPrice as decimal no-undo.
define variable vSoRecid as recid no-undo.
define variable vSodRecid as recid no-undo.
define variable vSodlcRecid as recid no-undo.
define variable vAbslRecid as recid no-undo.
define variable vProgramName as character no-undo.
define variable vAbsQty as decimal no-undo.

define buffer bf_abs for abs_mstr.

vAbsQty = 1.

for first bf_abs no-lock where
   bf_abs.abs_id = pAbsId and
   bf_abs.abs_shipfrom = pShipFrom:

   vAbsQty = if abs_ship_qty <> 0 then
             (if bf_abs.abs_ship_qty < 0 then -1 else 1)
              else 1.
end.

for each absl_det exclusive-lock where
   absl_abs_id = pAbsId           and
   absl_abs_shipfrom = pShipFrom  and
   absl_order = pOrder            and
   absl_ord_line = pOrderLine:

   if not pForASN then do:
      if not pConfirm then
         assign
            absl_inv_post = no
            absl_inv_nbr = "".

      if pConfirm then
         absl_confirmed = pConfirm.
   end.

   if absl_charge_type <> "" then do:

      assign
         vSoRecid = ?
         vSodRecid = ?
         vSodlcRecid = ?
         vAbslRecid  = recid(absl_det).

      if pForASN then
         assign
            vLineUnitCharge = absl_lc_amt
            vLinePrice = (absl_lc_amt * vAbsQty).
      else
         assign
            vLineUnitCharge = absl_lc_amt
            vLinePrice = if pConfirm then (absl_lc_amt * vAbsQty)
                      else
                         (if auto_post then ((absl_lc_amt * -1) * vAbsQty)
                         else 0).

      for first so_mstr no-lock where so_nbr = pOrder:
         vSoRecid = recid(so_mstr).
      end.

      for first sod_det fields(sod_nbr sod_line) no-lock where
         sod_nbr = pOrder and
         sod_line = pOrderLine:
         vSodRecid = recid(sod_det).
      end.

      for first sodlc_det fields(sodlc_order sodlc_ord_line sodlc_lc_line)
         no-lock
         where sodlc_order = pOrder
         and sodlc_ord_line = pOrderLine
         and sodlc_lc_line = absl_lc_line:
         vSodlcRecid = recid(sodlc_det).
      end.

      {pxrun.i &PROC  = 'updateChargeTypePrice'
               &PROGRAM = 'cclcxr.p'
               &HANDLE = ph_cclcxr
               &PARAM = "(input absl_charge_type,
                          input no,
                          input-output vLineUnitCharge,
                          input vSoRecid,
                          input vSodRecid,
                          input vSodlcRecid,
                          input pAbsRecid,
                          input vAbslRecid,
                          output vLinePrice)"}
      assign
         absl_lc_amt = vLineUnitCharge
         absl_ext_price = vLinePrice.
   end.

   else do:
      if not pForASN then
         absl_ext_price = if pConfirm then (absl_lc_amt * vAbsQty)
                          else
                             (if auto_post then ((absl_lc_amt * -1) * vAbsQty)
                                else 0).
      if pForASN then
         absl_ext_price = (absl_lc_amt * vAbsQty).
   end.
end. /* FOR EACH ABSL_DET */
